package com.jbh.wanandroidkotlin.activity


import android.graphics.Bitmap
import android.os.Bundle
import android.text.TextUtils
import android.webkit.WebView
import android.widget.LinearLayout
import com.jbh.wanandroidkotlin.R
import com.jbh.wanandroidkotlin.util.WEB_LINK
import com.jbh.wanandroidkotlin.util.data
import com.just.agentweb.AgentWeb
import com.just.agentweb.WebChromeClient
import com.just.agentweb.WebViewClient
import kotlinx.android.synthetic.main.activity_common_.*

class CommonActivity : BaseActivity() {

//    private var mAgentWeb: AgentWeb? = null
    private var webLink: String? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_)
        initView()
        init()
    }


    private fun initView() {

    }


    private fun init() {
        val b = intent.getBundleExtra(data)
        webLink = b?.getString(WEB_LINK)
//        mAgentWeb = AgentWeb.with(this)
//            .setAgentWebParent(f_content, LinearLayout.LayoutParams(-1, -1))
//            .useDefaultIndicator(0, 0)
//            .setSecurityType(AgentWeb.SecurityType.DEFAULT_CHECK)
//            .setWebChromeClient(mWebChromeClient)
//            .setWebViewClient(mWebViewClient)
//            .createAgentWeb()
//            .ready()
//            .go(webLink)
//                mAgentWeb.getJsInterfaceHolder().addJavaObject("android", new AndroidInterface(mAgentWeb,this));

        AgentWeb.with(this)
            .setAgentWebParent(f_content, LinearLayout.LayoutParams(-1, -1))
            .useDefaultIndicator()
            .createAgentWeb()
            .ready()
            .go(webLink)
    }



    /**
     * js 調用 java
     */
    class AndroidInterface(var agent: AgentWeb) {
    }


    /**
     * Java调用js
     *
     * @param methodName
     */
    fun callJs(methodName: String?) {
//        mAgentWeb!!.jsAccessEntrace.quickCallJs(methodName)
    }




    private val mWebViewClient: WebViewClient = object : WebViewClient() {

        override fun onPageStarted(view: WebView, url: String, favicon: Bitmap) {

        }

        override fun onPageFinished(view: WebView, url: String) {
            super.onPageFinished(view, url)
//            mAgentWeb!!.indicatorController.finish()
        }
    }


    private val mWebChromeClient: WebChromeClient = object : WebChromeClient() {

        override fun onProgressChanged(view: WebView, newProgress: Int) {

        }
    }




    override fun onResume() {
//        mAgentWeb!!.webLifeCycle.onResume()
        super.onResume()
    }

    override fun onPause() {
//        mAgentWeb!!.webLifeCycle.onPause()
        super.onPause()
    }

    override fun onDestroy() {
//        mAgentWeb!!.webLifeCycle.onDestroy()
        super.onDestroy()
    }
}